package com.hz.service.impl;

import com.hz.mbg.mapper.TbBannerMapper;
import com.hz.mbg.entity.TbBanner;
import com.hz.mbg.entity.TbBannerExample;
import com.hz.service.BannerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import java.util.List;

@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private TbBannerMapper bannerMapper;

    @Override
    public List<TbBanner> listBybannerposition() {
        TbBannerExample example = new TbBannerExample();
        example.setOrderByClause("bannerposition ASC");

        return bannerMapper.selectByExample(example);
    }

    @Override
    public int add(TbBanner banner) {
        return bannerMapper.insertSelective(banner);
    }

    @Override
    public int update(Integer bannerid, TbBanner banner) {
        banner.setBannerid(bannerid);
        return bannerMapper.updateByPrimaryKeySelective(banner);
    }

    @Override
    public int delete(Integer bannerid) {
        return bannerMapper.deleteByPrimaryKey(bannerid);
    }

    @Override
    public List<TbBanner> list(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return bannerMapper.selectByExample(new TbBannerExample());
    }

    @Override
    public TbBanner get(Integer bannerid) {
        return bannerMapper.selectByPrimaryKey(bannerid);
    }
}
